<template>
    <div class="dest-main-wrap">
        <div class="dest_box">
            <h2>目的地筛选</h2>
            <!-- 出行时间选择 -->
            <div class="time">
                <div class = "time_title">时间</div>
                <div class="time_list">
                    <div class="month" >
                        <span v-for = "(item, i) of dest_list['时间']" :key="i">
                            <span class = "month_item" @click = "filter( '/destCardSelect', item)" :class = "{active: item == time ? true: false}">{{item}}</span><b>|</b>
                        </span>
                    </div>
                    <div class="festival">
                        <span v-for = "(item, i) of dest_list['节日']" :key="i">
                            <span class = "festival_item" @click = "filter( '/destCardSelect', item)" :class = "{active: item == time ? true: false}">{{item}}</span><b>|</b>
                        </span>
                    </div>
                </div>    
            </div>


            <!-- 出行主题选择 -->
            <div class="sub">
                <div class="sub_title">主题</div>
                <div class="sub_list">
                    <span :class = "{active: '免签' == style ? true: false}" class = "sub_item">免签</span><b>|</b>
                    <div class="line_box">
                        <div class="line_1">
                            <div class="line_1_title">全年适宜：</div>
                            <div class="line_1_list">
                                <span v-for = "(item, i) of dest_list['全年适宜']" :key="i">
                                    <span @click = "filter( '/destCardSelectZT', item)" :class = "{active: item == style ? true: false}" class = "sub_item">{{item}}</span><b>|</b>
                                </span>
                                
                            </div>
                        </div>

                        <div class="line_1">
                            <div class="line_1_title">季节：</div>
                            <div class="line_1_list">
                                <span v-for = "(item, i) of dest_list['季节']" :key="i">
                                    <span @click = "filter( '/destCardSeason' , item)" :class = "{active: item == season ? true: false}" class = "sub_item">{{item}}</span><b>|</b>
                                </span>
                                
                            </div>
                        </div>
                        <div class="line_1">
                            <div class="line_1_title">出行方式：</div>
                            <div class="line_1_list">
                                <span v-for = "(item, i) of dest_list['出行方式']" :key="i">
                                    <span @click = "filter( '/destCardMode', item)" :class = "{active: item == way ? true: false}" class = "sub_item">{{item}}</span><b>|</b>
                                </span>
                                
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>

        </div>



        <!-- 底部卡片 -->
        <div class="card_box">
            <div class="dest-main-card" v-for="(item,index) of card_data" :key="index" @click="detail(item.id)" >
                <div class="img">
                    <el-image :src="item.image"   lazy></el-image>
                    <div class = "img_title">{{item.address}}</div>
                </div>
                <div class="des">
                    <h4>{{item.title}}</h4>
                    <div class="des_reco">
                        <span class = "top">TOP3</span>
                        <span class = "reco_item">{{item.lable.split(" ")[1]}} </span><b>|</b>
                        <span class = "reco_item">{{item.lable.split(" ")[2]}} </span><b>|</b>
                        <span class = "reco_item">{{item.lable.split(" ")[3]}}</span>
                    </div>
                    <div class="xl">
                        <!-- <span class = "num">1</span ><span class = "xljs">巴厘岛新晋网红5日线路</span> -->
                    </div>
                </div>
                
            </div> 
        </div>
        
        

        <!-- 分页按钮 -->
        <div class="test">
            <el-pagination
            :page-size="12"
            :pager-count = "5"
            :current-page.sync = "current_page"
            layout="prev, pager, next"
            :total="total"
            @current-change = "change_btn">
            
            </el-pagination>
        </div>
        
        
        
    </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
    name: 'WorkspaceJsonMain',
    

    data() {
        return {
            time: '1月',
            style: '免签',
            season: '草原',
            way: '徒步',
            card_data: [],
            dest_list: {
                '时间': ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                '节日': ['元旦', '春节', '清明', '五一', '端午', '中秋', '国庆', '寒假', '暑假'],
                '全年适宜': ['人文历史', '拍片圣地', '自然风景', '小众', '登山', '潜水', '古镇', '动物', '逃离雾霾', '购物', '美食', '漂流', '蹦极', '跳伞'],
                '季节': ['草原', '星空', '赏花', '雪景', '海岛', '极限运动', '滑雪', '温泉', '当地节庆', '温暖地点', '避暑', '极光'],
                '出行方式': ['徒步', '自驾', '游轮', '骑行', '蜜月', '亲子游', '带父母', '一个人', '好朋友']
            },
            page_sum: 0,
            page: '1',
            req_methods: '',
            total: 0,
            current_page: 1
           
        };
    },

    async mounted() {
        await this.filter('/destCardPage',); 

        // console.log(this.$route.query);
        // let title = this.$route.query.title
        // await this.getSearch(title)

        // this.test = this.$store.getters.get_dest_detail;
    },
    // computed:         mapState({card: state => state.dest_detail}),
    computed: {
        ...mapState(["dest_detail"])
    },
    watch: {
        dest_detail: {
            handler: function(val, oldval) {
                this.card_data = val;
                this.total = 12;
            },
            deep: true
        }
    },
    

    methods: {
        detail(id){
            console.log(id);
            this.$router.push('/dest/detail?id='+id)
        },
        
        
        filter(url, methods, i) {                       //封装筛选函数
                          
            if(i == undefined) {                   
                i = 1;
                this.current_page = 1;
            }
            if(url == '/destCardPage') {                //根据请求地址不同判断请求的类别
                this.req_methods = "show_card";            //并做出标记，方便下边分页按钮传参的判断
            }
            if(url == '/destCardSelect') {
                this.meth = methods;
                this.req_methods = "change_time";   
            } else if(url == '/destCardSelectZT') {
                this.meth = methods;
                this.req_methods = "change_style";   
            } else if(url == '/destCardSeason') {
                this.meth = methods;
                this.req_methods = "change_season";

            } else if(url == '/destCardMode') {
                this.meth = methods;
                this.req_methods = "change_way";   
            }
            
            this.$http.post(url , {mid: i, way: methods}).then(result => {
                this.card_data = result.data.data;
                this.page_sum = result.data.pages;
                this.total = parseInt(result.data.num[0].num);
                
                    
            })
        },
        change_btn(i) {             //按下按钮同时调用函数刷新页面  
            if(this.req_methods == "show_card") {
                this.filter( '/destCardPage' , 0, i);
            } else if(this.req_methods == "change_time") {
                this.filter( '/destCardSelect' , this.meth, i);
            } else if(this.req_methods == "change_style") {
                this.filter( '/destCardSelectZT' , this.meth, i);
            } else if(this.req_methods == "change_season") {
                this.filter( '/destCardSeason' , this.meth, i);
            } else if(this.req_methods == "change_way") {
                this.filter( '/destCardMode' , this.meth, i);
            }
            window.scrollTo(0, 1010);

        },
        getSearch(title){
        this.$http.post('/destSearch',{
            title
        }).then(res=>{
            console.log(res);
            this.card_data = res.data.data
        }).catch(err=>{
            throw err
        })
        }
        
    },
    created(){
        // console.log(this.$route.query);
        // let title = this.$route.query.title
        // this.$http.post('/destSearch',{
        //     title
        // }).then(res=>{
        //     console.log(res);
        //     this.card_data = res.data.data
        // }).catch(err=>{
        //     throw err
        // })
    }
};
</script>

<style lang="scss" scoped>
.dest-main-wrap{
    width: 1200px;
    min-height: 800px;
    box-sizing: border-box;
    margin: 0 auto;
    // background: rgb(90, 231, 219);
    
    .dest_box {
        width: 100%;
        // height: 500px;
        // border: 1px solid #ccc;
        padding-bottom: 30px;
        border-bottom: 1px solid #ccc;
        margin-top: 50px;
        h2 {
            font-size: 24px;
            color: #333;
            font-weight: 400;
            margin-bottom: 30px;
        }
        // 出行时间
        .time {
            display: flex;
            border-bottom: 1px dashed #efefef;
            .time_title {
                width: 45px;
                color: #333;
                font-size: 16px;
            }
            .time_list {
                width: 1100px;
                color: #666;
                font-size: 14px;
                .month_item, .festival_item {
                    display: inline-block;
                    margin: 0 20px 15px 20px;
                    cursor: pointer;
                    &:hover {
                        color: #41c1ec;
                        text-decoration: underline;
                    }
                }
                .active {
                    color: #41c1ec;
                    text-decoration: underline;
                }
                b {
                    font-weight: 100;
                    color: #666;
                }
            }
        }
        // 出行主题
        .sub {
            display: flex;
            // border-bottom: 1px dashed #efefef;
            margin-top: 15px;
            .sub_title {
                width: 45px;
                // background: blue;
                color: #333;
                font-size: 16px;
            }
            .sub_list {
                width: 1100px;
                // background: red;
                color: #666;
                font-size: 14px;
                display: flex;
                .sub_item {
                    display: inline-block;
                    margin: 0 19px 15px 19px;
                    cursor: pointer;
                    color: #666;
                    &:hover {
                        color: #41c1ec;
                        text-decoration: underline;
                    }
                }
                .active {
                    color: #41c1ec;
                    text-decoration: underline;
                }
                b {
                    font-weight: 100;
                    color: #666;
                }
                .line_1 {
                    display: flex;
                    .line_1_title {
                        width: 70px;
                        margin-left: 20px;
                        color: #333;
                        font-size: 14px
                    }
                    .line_1_list {
                        width: 935px;
                    }
                }

            }
        }
    } 
    // 底部卡片
    .card_box {
        margin-top: 30px;
        display: flex;
        flex-wrap: wrap;
        .dest-main-card{
            width: 320px;
            border: 1px solid #f2f2f2 ;
            height: 360px;
            margin: 0 39px 20px;
            &:hover {
                box-shadow: 0 0 5px 5px #f2f2f2;
            }
            .img {
                width: 100%;
                height: 200px;
                position: relative;
                font-size: 0;
                img {
                    width: 100%;
                }
                .img_title {
                    position: absolute;
                    bottom: 0;
                    left: 0;
                    right: 0;
                    color: white;   
                    font-size: 24px;
                    text-align: center;
                    padding: 30px 0;
                    font-weight: 400;
                    // transform: translate(-50%, 0);
                    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(0, 0, 0, 0)), color-stop(100%, rgba(0, 0, 0, 0.8))) ;
                    
                }
            }
            .des {
                padding: 15px;
                h4 {
                    font-size: 14px;
                    height: 37px;
                    color: #333;
                    font-weight: 400; 
                }
                .des_reco {  
                    font-size: 14px;
                    color: #666;
                    line-height: 46px;
                    margin: 12px 0;
                    border-top: 1px solid #f5f5f5;
                    border-bottom: 1px solid #f5f5f5;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    .top {
                        color: #41c1ec;
                    }
                    b {
                        font-weight: 100;
                    }
                    .reco_item {
                        cursor: pointer;
                        margin: 0 5px;
                        &:hover{
                            color: #41c1ec;
                            text-decoration: underline;
                        }
                    }
                }
                .xl {
                    font-size: 14px;
                    color: #666;
                    .num {
                        display: inline-block;
                        width: 14px;
                        height: 14px;
                        line-height: 14px;
                        color: white;
                        background: #a4d5f1;
                        text-align: center;
                    }
                    .xljs {
                        margin-left: 10px;
                        cursor: pointer;
                        &:hover {
                            color: #41c1ec;
                            text-decoration: underline; 
                        }
                    }
                }
            }
            
        } 
    }
    .test {
        text-align: center;
    }
    
}
</style>